import permision from './permission.js'

// android.permission.ACCESS_FINE_LOCATION				位置权限
// android.permission.ACCESS_COARSE_LOCATION			模糊位置权限(蓝牙\ble依赖)
// android.permission.CAMERA							摄像头权限
// android.permission.READ_EXTERNAL_STORAGE				外部存储(含相册)读取权限
// android.permission.WRITE_EXTERNAL_STORAGE			外部存储(含相册)写入权限
// android.permission.RECORD_AUDIO						麦克风权限
// android.permission.READ_CONTACTS						通讯录读取权限
// android.permission.WRITE_CONTACTS					通讯录写入权限
// android.permission.READ_CALENDAR						日历读取权限
// android.permission.WRITE_CALENDAR					日历写入权限
// android.permission.READ_SMS							短信读取权限
// android.permission.SEND_SMS							短信发送权限
// android.permission.RECEIVE_SMS						接收新短信权限
// android.permission.READ_PHONE_STATE					获取手机识别码等信息的权限
// android.permission.CALL_PHONE						拨打电话权限
// android.permission.READ_CALL_LOG						获取通话记录权限

// 1	已获取授权
// 0	未获取授权
// -1	被永久拒绝授权

// 判断权限是否开启
async function requestAndroidPermission(permisionID) {
  var result = await permision.requestAndroidPermission(permisionID)

  var permisionID_Name

  if (permisionID == 'android.permission.ACCESS_FINE_LOCATION') {
    permisionID_Name = '位置权限'
  }
  if (permisionID == 'android.permission.ACCESS_COARSE_LOCATION') {
    permisionID_Name = '模糊位置权限(蓝牙\ble依赖)'
  }
  if (permisionID == 'android.permission.CAMERA') {
    permisionID_Name = '摄像头权限'
  }
  if (permisionID == 'android.permission.READ_EXTERNAL_STORAGE') {
    permisionID_Name = '外部存储(含相册)读取权限'
  }
  if (permisionID == 'android.permission.WRITE_EXTERNAL_STORAGE') {
    permisionID_Name = '外部存储(含相册)写入权限'
  }

  if (permisionID == 'android.permission.RECORD_AUDIO') {
    permisionID_Name = '麦克风权限'
  }
  if (permisionID == 'android.permission.READ_CONTACTS') {
    permisionID_Name = '通讯录读取权限'
  }
  if (permisionID == 'android.permission.WRITE_CONTACTS') {
    permisionID_Name = '通讯录写入权限'
  }
  if (permisionID == 'android.permission.READ_CALENDAR') {
    permisionID_Name = '日历读取权限'
  }
  if (permisionID == 'android.permission.WRITE_CALENDAR') {
    permisionID_Name = '日历写入权限'
  }

  if (permisionID == 'android.permission.READ_SMS') {
    permisionID_Name = '短信读取权限'
  }
  if (permisionID == 'android.permission.SEND_SMS') {
    permisionID_Name = '短信发送权限'
  }
  if (permisionID == 'android.permission.RECEIVE_SMS') {
    permisionID_Name = '接收新短信权限'
  }
  if (permisionID == 'android.permission.READ_PHONE_STATE') {
    permisionID_Name = '获取手机识别码等信息的权限'
  }
  if (permisionID == 'android.permission.CALL_PHONE') {
    permisionID_Name = '拨打电话权限'
  }

  if (permisionID == 'android.permission.READ_CALL_LOG') {
    permisionID_Name = '获取通话记录权限'
  }

  if (permisionID == 'android.permission.RECEIVE_WAP_PUSH') {
    permisionID_Name = '获取推送消息权限'
  }
  if (permisionID !== 'android.permission.RECEIVE_WAP_PUSH') {
    var strStatus
    if (result == 1) {
      strStatus = '已获得授权'
    } else if (result == 0) {
      strStatus = '未获得授权'
      uni.showToast({
        title: permisionID_Name + strStatus,
        icon: 'none',
      })
    } else {
      strStatus = '被永久拒绝权限'
      uni.showModal({
        title: '提示',
        content: permisionID_Name + strStatus + ',是否进入设置启用',
        success: function (res) {
          if (res.confirm) {
            permision.gotoAppPermissionSetting()
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        },
      })
    }
    return result
  }
}

export default {
  requestAndroidPermission: requestAndroidPermission,
  judgeIosPermission: permision.judgeIosPermission,
}
